# -*- coding = utf-8 -*-
# @Time : 2021/7/14 17:22
# @Author : 龙王赘婿_彪少
# @File : testUrllib5.py
# @Software: PyCharm

import urllib.request
import urllib.parse
#伪装

# 打开网址，F12，找到网络格，刷新一下，回到时间线前面，www.baidu.com，
# 在标头里查看就可以了，找到User-Agent:


#url = "https://www.douban.com"
url = "http://httpbin.org/post"

headers = {
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
}

data = bytes(urllib.parse.urlencode({"name":"liu"}), encoding = "utf-8")

req = urllib.request.Request(url=url, data=data, headers=headers, method="POST")

response = urllib.request.urlopen(req)

#打印请求
# print(req)
#获取状态码 200 404 418茶壶
# print(response.status)
#获取数据头
# print(response.getheaders())
#获取数据头的单个数据
# print(response.getheader("Date"))
#获取数据体
print(response.read().decode('utf-8'))